package com.bysj.yqsht.web.controller;


import com.bysj.yqsht.bean.MatchsApply;
import com.bysj.yqsht.bean.extend.MatchsApplyExtend;
import com.bysj.yqsht.service.IMatchsApplyService;
import com.bysj.yqsht.utils.Message;
import com.bysj.yqsht.utils.MessageUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("matchApply")
@Api(description = "竞赛报名管理")
public class MatchsApplyController {
    @Autowired
    private IMatchsApplyService matchApplyService;

    @GetMapping("findAll")
    public Message findAll(){
        List<MatchsApply> MatchsApply = matchApplyService.findAll();
        return MessageUtil.success(MatchsApply);

    }

    @GetMapping("findWithAll")
    public Message findWithAll(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int limit){
        List<MatchsApplyExtend> MatchsApply = matchApplyService.findWithAll(pageNum,limit);
        return MessageUtil.success(MatchsApply);
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(MatchsApply matchsApply){
        matchApplyService.saveOrUpdate(matchsApply);
        return MessageUtil.success("修改或新增成功");
    }

    @GetMapping("deleteById")
    public Message deleteById(long id){
        matchApplyService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @GetMapping("findWithAllBy")
    public Message findWithAllBy(Long matchId,Long studentId){
        List<MatchsApplyExtend> list = matchApplyService.findWithAllBy(matchId,studentId);
        return MessageUtil.success(list);
    }

}
